/**
 * @file app.js
 * @author swan
 */
/* globals swan */
App({
    data(){
    },
    onLaunch(options) {
        // do something when launch
    },
    onShow(options) {
        // do something when show
    },
    onHide() {
        // do something when hide
    },
    goToDetails(item){
        console.log(item)
        let id = item.currentTarget.dataset.item.id
        // let classId = item.currentTarget.dataset.item.classid
        console.log(id)
        if( item.currentTarget.dataset.id == id ){
            return false
        }else{
            swan.navigateTo({
                url: "/pages/details/details?id=" + id
            });
        }
    },
    goToList(item,scrollleft){
        // console.log(item)
        if( item.currentTarget.dataset.item.name == "首页" ){
            swan.navigateTo({
                url: "/pages/index/index"
            });
        }else{
            let id = item.currentTarget.dataset.item.id
            let classname = item.currentTarget.dataset.item.name
            swan.navigateTo({
                url: "/pages/list/list?id=" + id + "&classname=" + classname + "&left=" + scrollleft
            });
        }
    },
    getTdk(site){
        // console.log(site)
        let img = (site != undefined && site.img != undefined) ? site.img : ""
        if( site != undefined ){
            swan.setPageInfo({
                title: site.title,
                keywords: site.sitekey,
                description: site.siteintro,
                image: img,
                success: function () {
                    console.log('setPageInfo success');
                  },
                  fail: function (err) {
                      console.log('setPageInfo fail', err);
                  }
              })
        }
    },
    showToast(itemtitle) {
        swan.showToast({
            title: itemtitle,
            mask: false,
            success: res => {
                this.setData({'disabled': false});
            },
            fail: err => {
                console.log('showToast fail', err);
            }
        });
    }
});
